package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.JsonResult;
import cn.wolfcode.service.IEmployeeService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("resetPassword")
public class ResetPasswordController {
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("resetPwd")
    public String returnjsp (Long id, Model model) {
        Employee employee = employeeService.selectById(id);
        model.addAttribute("employee", employee);
        return "/common/resetPwd";
    }

    @RequestMapping("resetPas")
    public String resetPwd (Long id, String newPassword) {
        Employee employee = employeeService.selectById(id);
        //那么将从前台获取到的新密码加密
        Md5Hash md5HashNewPwd = new Md5Hash(newPassword, employee.getName());
        employeeService.updateNewPassword(id, md5HashNewPwd.toString());
        return "redirect:/employee/list.do";
    }


}
